console.log('====================================')
console.log(process.env.NODE_ENV, process.env.ENV)
console.log(process.env.VUE_APP_BASE_API)
console.log(process.env.VUE_CLI_BABEL_TRANSPILE_MODULES)
console.log('========********======******======================')
const CompressionWebpackPlugin = require('compression-webpack-plugin')
module.exports = {
  publicPath: process.env.NODE_ENV === 'production' ? './' : '/',
  outputDir: 'dist',
  assetsDir: 'static',
  productionSourceMap: false,
  configureWebpack: (config) => {
    if (process.env.NODE_ENV === 'production') {
      config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
    }
  },
  chainWebpack: (config) => {
    config.when(process.env.NODE_ENV === 'production', (config) => {
      config.plugin('compressionPlugin').use(new CompressionWebpackPlugin({
        test:/\.js$|\.html$|.\css/, // 匹配文件名
        threshold: 10240, // 对超过10k的数据压缩
        deleteOriginalAssets: false // 不删除原资源
      }))
    })
    config.when(process.env.NODE_ENV !== 'development', (config) => {
      config.optimization.splitChunks({
        chunks: 'all',
        cacheGroups: {
          libs: {
            name: 'chunk-libs',
            test: /[\\/]node_modules[\\/]/,
            priority: 10,
            chunks: 'initial' // only package third parties that are initially dependent
          },
          elementUI: {
            name: 'chunk-elementUI', // split elementUI into a single package
            priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
            test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
          }
        }
      })
      config.optimization.runtimeChunk('single')
    })
  },
  devServer: {
    port: 8081,
    hot: true,
    clientLogLevel: 'info',
    proxy: {
      [process.env.VUE_APP_BASE_API]: {
        target: 'http://172.10.102.120:9025',
        changeOrigin: true,
        pathRewrite: {
          ['^' + process.env.VUE_APP_BASE_API]: ''// 不想始终传递 /api ，则需要重写路径
        }
      }
    }
  }
}